package me.shurufa.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import me.shurufa.R;
import me.shurufa.bean.Book;
import me.shurufa.fragments.BookDetailFragment;
import me.shurufa.utils.Constants;
import me.shurufa.utils.StatusBarCompat;

/**
 * 作者 : andy
 * 日期 : 16/3/8 17:50
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 首页所有Menu Fragment内的图书点击都进入到图书的详情界面
 */
public class BookDetailActivity extends BaseActivity {

    private Book mBook;
    private int mWhereFrom;
    private String mUserId;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_book_detail;
        super.onCreate(savedInstanceState);
        parseArguments();
        initFragment();
    }

    private void parseArguments() {
        mWhereFrom = getIntent().getIntExtra(Constants.ARG_FROM_WHERE, Constants.TYPE_FRAGMENT_NEWEST_BOOK);
        mUserId = getIntent().getStringExtra(Constants.ARG_USER_ID);
        mBook = (Book) getIntent().getSerializableExtra(Constants.ARG_BOOK);
    }

    private void initFragment() {
        BookDetailFragment fragment = BookDetailFragment.newInstance(mBook, mWhereFrom, mUserId);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.fragment_container, fragment);
        transaction.commit();
    }

    @Override
    public void initStatusBar() {
        StatusBarCompat.setColor(this, getResources().getColor(R.color.red_new), 0);
    }
}
